package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OaPaymentAccounts;
import com.ruoyi.system.service.IOaPaymentAccountsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付账号Controller
 *
 * @author ruoyi
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/system/accounts")
@Transactional
public class OaPaymentAccountsController extends BaseController
{
    @Autowired
    private IOaPaymentAccountsService oaPaymentAccountsService;

    /**
     * 查询支付账号列表
     */
    @PreAuthorize("@ss.hasPermi('system:accounts:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaPaymentAccounts oaPaymentAccounts)
    {
        startPage();
        List<OaPaymentAccounts> list = oaPaymentAccountsService.selectOaPaymentAccountsList(oaPaymentAccounts);
        return getDataTable(list);
    }

    /**
     * 导出支付账号列表
     */
    @PreAuthorize("@ss.hasPermi('system:accounts:export')")
    @Log(title = "支付账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaPaymentAccounts oaPaymentAccounts)
    {
        List<OaPaymentAccounts> list = oaPaymentAccountsService.selectOaPaymentAccountsList(oaPaymentAccounts);
        ExcelUtil<OaPaymentAccounts> util = new ExcelUtil<OaPaymentAccounts>(OaPaymentAccounts.class);
        util.exportExcel(response, list, "支付账号数据");
    }

    /**
     * 获取支付账号详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:accounts:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(oaPaymentAccountsService.selectOaPaymentAccountsById(id));
    }

    /**
     * 新增支付账号
     */
    @PreAuthorize("@ss.hasPermi('system:accounts:add')")
    @Log(title = "支付账号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaPaymentAccounts oaPaymentAccounts)
    {
        return toAjax(oaPaymentAccountsService.insertOaPaymentAccounts(oaPaymentAccounts));
    }

    /**
     * 修改支付账号
     */
    @PreAuthorize("@ss.hasPermi('system:accounts:edit')")
    @Log(title = "支付账号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaPaymentAccounts oaPaymentAccounts)
    {
        return toAjax(oaPaymentAccountsService.updateOaPaymentAccounts(oaPaymentAccounts));
    }

    /**
     * 删除支付账号
     */
    @PreAuthorize("@ss.hasPermi('system:accounts:remove')")
    @Log(title = "支付账号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oaPaymentAccountsService.deleteOaPaymentAccountsByIds(ids));
    }
    //根据项目负责人姓名获取支付账户
    @GetMapping(value = "/filler")
    public AjaxResult filler( String filler)
    {
        OaPaymentAccounts oaPaymentAccounts = new OaPaymentAccounts();
        oaPaymentAccounts.setUsername(filler);
        List<OaPaymentAccounts> oaPaymentAccounts1 = oaPaymentAccountsService.selectOaPaymentAccountsList(oaPaymentAccounts);
        return success(oaPaymentAccounts1);
    }
    @GetMapping("/list1")
    public TableDataInfo list1()
    {
        OaPaymentAccounts oaPaymentAccounts = new OaPaymentAccounts();
        LoginUser loginUser = SecurityUtils.getLoginUser();
        oaPaymentAccounts.setUsername(loginUser.getUsername());
        List<OaPaymentAccounts> list = oaPaymentAccountsService.selectOaPaymentAccountsList(oaPaymentAccounts);
        return getDataTable(list);
    }
}
